package top.chj.day16.dateclass;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalQuery;

/**
 * @Auther:小陈的Java
 */
public class TemporalQueryDemo implements TemporalQuery<Long> {
    @Override
    public Long queryFrom(TemporalAccessor temporal) {
        LocalDate localDate = LocalDate.from(temporal);
        LocalDate laborDate = LocalDate.of(localDate.getYear(),5,1);
        if(localDate.isAfter(laborDate)){
            laborDate = laborDate.plusYears(1);
        }
        long result = ChronoUnit.DAYS.between(localDate,laborDate);
        return result;
    }

    public static void main(String[] args) {
        LocalDate localDate = LocalDate.of( 2012,5,2);
        Long result = localDate.query(new TemporalQueryDemo());
        System.out.println(result);
    }
}
